1 using UnityEngine;
2
3 public
class RandomMatchmaker : Photon.MonoBehaviour
4 {
5     
private PhotonView myPhotonView;
6
7     
// Use this for initialization
8     
void Start()
9     {
10         PhotonNetwork.ConnectUsingSettings(
"0.1");
11     }
12
13     
void OnJoinedLobby()
14     {
15         Debug.Log(
"JoinRandom");
16         PhotonNetwork.JoinRandomRoom();
17     }
18
19     
void OnPhotonRandomJoinFailed()
20     {
21         PhotonNetwork.CreateRoom(
null);
22     }
23
24     
void OnJoinedRoom()
25     {
26         GameObject monster = PhotonNetwork.Instantiate(
"monsterprefab", Vector3.zero, Quaternion.identity, 0);
27         monster.GetComponent<myThirdPersonController>().isControllable =
true;
28         myPhotonView = monster.GetComponent<PhotonView>();
29     }
30
31     
void OnGUI()
32     {
33         GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
34
35         
if (PhotonNetwork.connectionStateDetailed == PeerState.Joined)
36         {
37             
bool shoutMarco = GameLogic.playerWhoIsIt == PhotonNetwork.player.ID;
38
39             
if (shoutMarco && GUILayout.Button("Marco!"))
40             {
41                 myPhotonView.RPC(
"Marco", PhotonTargets.All);
42             }
43             
if (!shoutMarco && GUILayout.Button("Polo!"))
44             {
45                 myPhotonView.RPC(
"Polo", PhotonTargets.All);
46             }
47         }
48     }
49 }


Use this for initialization




Trò chơi Tic-Tac-Toe, game đánh caro full source code 53.543 lượt xem

Gõ tìm kiếm nhanh...